$(function () {
    getImageInfo();
    gotoTop();
})
var prefix = "/home/productBrowsing"

function getImageInfo() {
    var ncFileId = $("#imageProductId").val();
    var tbody = $("#tbody");
    $.ajax({
        type: "post",
        async: true,
        url: prefix+"/getImageList",
        data: {
            "ncFileId": ncFileId,
        },
        dataType: "json",        //返回数据形式为json
        success: function (data) {
            tbody.empty();
            result = data.data;
            for (var i = 0; i < result.length; i++) {
                tbody.append('<tr>');
                tbody.append('<td class="prt_tab_1">' + result[i].fileName + '</td>');
                    tbody.append('<td class="prt_tab_1">' + result[i].fileSize + 'MB</td>' +
                        '<td class="prt_tab_1">' + paraseDate(result[i].updateDate) + '</td>' +
                        '<td class="prt_tab_2" width="180px"><a href="javascript:isPreview(\'' + result[i].filePath + ',' + result[i].fileName +'\')">预览</a>&nbsp;&nbsp;' +
                        '</td></tr>');
            }
        }
    });
}
//获取文件后缀
function getType(file){
    var filename=file;
    var index1=filename.lastIndexOf(".");
    var index2=filename.length;
    var type=filename.substring(index1,index2);
    return type;
}
function downLoad(unzipId) {
    if (!isLogin()) {
        showLoginDiv();
    } else {
        window.location.href = prefix+"/downloadUnzip&unzipId=" + unzipId;
    }
}
function isLogin() {
    var loginName = "[[${@permission.getPrincipalPropertyUnLogged('loginName')}]]";
    if (loginName){
        return true
    }else {
        return false
    }
}

function isStrInArray(str, arr) {
    var n = arr.length;
    for (var i = 0; i < n; i++) {
        if (arr[i] == str) {
            return true;
        }
    }
    return false;
}
function isPreview(params) {
        // window.open("http://localhost:8082/newOcean/introduce.do?onlineDownloadFile&fullfilename=" + params)
    // var previewUrl = originUrl + '&fullfilename=NEMO_24h_RTGSST_2015-2016-M03_mae.png';
    // window.open('http://127.0.0.1:8012/onlinePreview?url='+encodeURIComponent(previewUrl));
    layer.open({
        type: 2,
        title: '预览结果',
        shadeClose: true,
        shade: false,
        maxmin: true, //开启最大化最小化按钮
        resize: true,
        area: ['700px', '550px'],
        content: prefix+'/onlineDownloadFile&fullfilename=' + params
    });
}
function toOrderDownLoad(unzipId) {
    if (!isLogin()) {
        showLoginDiv();
    } else {
        $.ajax({
            type: "post",
            async: true,
            url: "introduce.do?unzipTransferToDownOrder",
            data: {
                "unzipId": unzipId
            },
            success: function (data) {
                var id = eval(data);
                if (id == '1') {
                    alert("已添加至下载器");
                } else if (id == '2') {
                    alert("该文件尚未下载完成，请下载完成后再添加");
                } else if (id == '3'){
                    alert("部门未下载文件达到上限，不能添加，请先下载未下载的文件再进行添加");
                } else {
                    alert("下载器添加文件失败");
                }
            }
        });
    }
}

function paraseDate(date) {
    if (date == undefined) {
        return "未知";
    }
    var y = date.year < 1900 ? 1900 + date.year : date.year;
    var m = date.month + 1;
    m = m < 10 ? '0' + m : m;
    var d = date.date;
    d = d < 10 ? ('0' + d) : d;
    var h = date.hours;
    h = h < 10 ? ('0' + h) : h;
    var min = date.minutes;
    min = min < 10 ? ('0' + min) : min;
    var s = date.seconds;
    s = s < 10 ? ('0' + s) : s;
    return y + '-' + m + '-' + d + ' ' + h + ':' + min + ':' + s;
}

